package com.egao.orderB.service.impl;

import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.JsonResult;
import com.egao.common.system.entity.User;
import com.egao.orderB.biz.TableColumnBiz;
import com.egao.orderB.biz.TableColumnUserBiz;
import com.egao.orderB.entity.TableColumn;
import com.egao.orderB.entity.TableColumnUser;
import com.egao.orderB.service.TableColumnUserService;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

//import com.egao.orderB.mapper.TableColumnUserMapper;
//import javax.transaction.Transactional;

/**
 * 用户表格显示列配置服务实现类
 * @author : Doman
 * @date : 2021-09-01 15:20:33
 * @version ：1.0
 */
@Service
public class TableColumnUserServiceImpl /*extends ServiceImpl<TableColumnUserMapper, TableColumnUser> */implements TableColumnUserService {

	@Autowired
	private TableColumnUserBiz tableColumnUserBiz;
	@Autowired
	private TableColumnBiz tableColumnBiz;

    /**
    @Override
    public PageResult<TableColumnUser> listPage(PageParam<TableColumnUser> page) {
        List<TableColumnUser> records = baseMapper.listPage(page);
        return new PageResult<>(records, page.getTotal());
    }

    @Override
    public List<TableColumnUser> listAll(Map<String, Object> page) {
        return baseMapper.listAll(page);
    } */

    @Override
    public JsonResult list(PageResult2<T> page, TableColumnUser tableColumnUser, User loginUser)  throws Exception{
        return tableColumnUserBiz.list(page,tableColumnUser,loginUser);
    }

    @Override
    public JsonResult list(TableColumnUser tableColumnUser, User loginUser) {
        List<TableColumnUser> list = tableColumnUserBiz.list(tableColumnUser,loginUser);
        if (list.size()==0) {
            List<TableColumn> list1 = tableColumnBiz.list(new TableColumn(), loginUser);
            for (TableColumn tableColumn : list1) {
                TableColumnUser tableColumnUser2 = new TableColumnUser();
                tableColumnUser2.setUserId(tableColumnUser.getUserId());
                tableColumnUser2.setColumnId(tableColumn.getId());
                tableColumnUser2.setShowIs("1");
                tableColumnUserBiz.save(tableColumnUser2, loginUser);
            }
            list = tableColumnUserBiz.list(tableColumnUser,loginUser);
        }
        return JsonResult.ok().setData(list);
    }

    @Override
    public JsonResult getById(TableColumnUser tableColumnUser) {
        return JsonResult.ok().setData(tableColumnUserBiz.getById(tableColumnUser));
    }

    @Transactional
    @Override
    public JsonResult save(TableColumnUser tableColumnUser, User loginUser) {
        if (tableColumnUserBiz.save(tableColumnUser, loginUser)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }

    @Transactional
    @Override
    public JsonResult update(TableColumnUser tableColumnUser, User loginUser) {
        if (tableColumnUserBiz.update(tableColumnUser, loginUser)) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }

    @Transactional
    @Override
    public JsonResult remove(TableColumnUser tableColumnUser, User loginUser) {
        if (tableColumnUserBiz.remove(tableColumnUser, loginUser)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }

}
